//==================================================================
//  Copyright (C) 2006  Davide Pasca
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//==================================================================
///
///
///
///
///
//==================================================================

#include <string>
#include "TestShader.h"

//==================================================================
static const std::string _shaders_header( RENDSHADER_MAKECODE(

	//==================================================================
	struct VSIN_PCTN
	{
		float3	_pos		: POSITION;
	};

	//==================================================================
	struct VSOUT_PTC
	{
		float4	_pos		: POSITION;
		float4	_col		: COLOR0;
		float4	_mypos		: TEXCOORD1;
	};

) );

//==================================================================
static const std::string _vtx_shader_code( RENDSHADER_MAKECODE(

	VSOUT_PTC main(	const VSIN_PCTN			input,
					const uniform float4x4	proj_obj_m,
					const uniform float4x4	view_obj_m )
	{
		VSOUT_PTC  output = (VSOUT_PTC)0;

		output._pos = mul( proj_obj_m, float4(input._pos, 1.0) );
		output._col = float4( 0.1, 0.1, 0.5, 1.0 );
		output._mypos = output._pos;

		return output;
	}
) );

//==================================================================
static const std::string _pix_shader_code( RENDSHADER_MAKECODE(

	//==================================================================
	float4 main( const VSOUT_PTC input ) : COLOR
	{
		float4	out_col;

		float	norm_depth = input._mypos.z / input._mypos.w;

		out_col = input._col;
		out_col.b = pow( norm_depth, 32 );
		//out_col.w = 0.5f;

		return out_col;
	}
) );

//==================================================================
///
//==================================================================
TestShader::TestShader( RendDevice *RDevice, RendM5D::Scene *RScenep ) :
	_RDevice(RDevice),
	_RScenep(RScenep),
	_VtxShaderp(0),
	_PixShaderp(0)
{

	RendShaderManager	&ShaderManager = _RDevice->_ShaderMng;

	std::string	vtx_code_full = _shaders_header + _vtx_shader_code;
	std::string	pix_code_full = _shaders_header + _pix_shader_code;

	_VtxShaderp = ShaderManager.CreateVertexShaderFromSource( vtx_code_full.c_str() );
	_proj_obj_m_shparam = _VtxShaderp->AddParam( "proj_obj_m" );
	_view_obj_m_shparam = _VtxShaderp->AddParam( "view_obj_m" );

	_PixShaderp = ShaderManager.CreatePixelShaderFromSource( pix_code_full.c_str() );
}